package com.cy.cy2025.net.retrofit

import okhttp3.Interceptor
import okhttp3.OkHttpClient
import okhttp3.Response
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

object RetrofitHelper {

    val testInfoRetrofit: Retrofit by lazy {
        Retrofit.Builder()
            .baseUrl("https://pv.sohu.com/")
            .client(
                OkHttpClient.Builder()
                .apply {

                    addInterceptor(object : Interceptor {
                        override fun intercept(chain: Interceptor.Chain): Response {
                            val originalRequest = chain.request()
                            val requestBuilder = originalRequest.newBuilder()
                                .addHeader(
                                    "User-Agent",
                                    "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36"
                                )
                            val request = requestBuilder.build()
                            return chain.proceed(request)
                        }
                    })
                }
                .build())
            .addConverterFactory(GsonConverterFactory.create())
            .build()
    }


    val jsonTestRetrofit: Retrofit by lazy {
        Retrofit.Builder()
            .baseUrl("https://jsonplaceholder.typicode.com/")
            .addConverterFactory(GsonConverterFactory.create())
            .build()
    }
}